# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=nose

pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.3.3
pkgrel=1
pkgdesc="A discovery-based unittest extension (mingw-w64)"
arch=('any')
license=('LGPL-2.1')
url="http://readthedocs.org/docs/nose/"
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools" "${MINGW_PACKAGE_PREFIX}-python3-setuptools")
source=("http://pypi.python.org/packages/source/n/nose/nose-${pkgver}.tar.gz")
md5sums=('42776061bf5206670cb819176dc78654')
 
build() {
  cd "$srcdir/nose-$pkgver"
  sed -i -e "s:man/man1:share/man/man1:g" setup.py
  
  cd "$srcdir"
  rm -rf python{2,3}-build
  for builddir in python{2,3}-build; do
    cp -r nose-$pkgver $builddir
    pushd $builddir
    ${MINGW_PREFIX}/bin/${builddir%-build} setup.py build
    popd
  done
}

package_python3-nose() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3-setuptools")

  pushd ${MINGW_PREFIX} > /dev/null
  local _mingw_prefix=`pwd -W`
  popd > /dev/null

  cd "$srcdir/python3-build"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} --root="$pkgdir" -O1

  rm -f ${pkgdir}${MINGW_PREFIX}/bin/nosetests{.exe,-script.py,.exe.manifest}
  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -e "s|${_mingw_prefix}|${MINGW_PREFIX}|g" -i ${_f}
  done
  rm -rf "${pkgdir}${MINGW_PREFIX}/share"
}
 
package_python2-nose() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools")

  pushd ${MINGW_PREFIX} > /dev/null
  local _mingw_prefix=`pwd -W`
  popd > /dev/null

  cd "$srcdir/python2-build"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root="$pkgdir" -O1

  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -e "s|${_mingw_prefix}|${MINGW_PREFIX}|g" -i ${_f}
  done
}

package_mingw-w64-i686-python2-nose() {
  install=${_realname}2-${CARCH}.install
  package_python2-nose
}

package_mingw-w64-i686-python3-nose() {
  install=${_realname}3-${CARCH}.install
  package_python3-nose
}

package_mingw-w64-x86_64-python2-nose() {
  install=${_realname}2-${CARCH}.install
  package_python2-nose
}

package_mingw-w64-x86_64-python3-nose() {
  install=${_realname}3-${CARCH}.install
  package_python3-nose
}
